package cn.tedu.cwfw.feedback.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.feedback.pojo.dto.FeedbackQuery;
import cn.tedu.cwfw.feedback.pojo.dto.SaveFeedbackFrom;
import cn.tedu.cwfw.feedback.pojo.vo.FeedbackVO;
import cn.tedu.cwfw.feedback.service.FeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cwfw/cutecircle/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    /**
     * 举报
     * @param saveFeedbackFrom 保存反馈表单
     */
    @PostMapping("saveFeedback")
    public JsonResult addFeedback(SaveFeedbackFrom saveFeedbackFrom) {
        log.debug("举报请求:入参{}", saveFeedbackFrom);
        feedbackService.saveReport(saveFeedbackFrom);
        return JsonResult.ok();
    }

    /**
     * 查询反馈详情
     * @param id 反馈id
     */
    @GetMapping("selectById/{id}")
    public JsonResult selectById(@PathVariable Long id) {
        log.debug("查询反馈详情:入参{}", id);
        FeedbackVO feedback = feedbackService.selectById(id);
        log.debug("查询反馈详情:入参{},出参{}", id, feedback);
        return JsonResult.ok(feedback);
    }

    /**
     * 查询反馈列表
     * @param feedbackQuery 反馈查询对象
     */
    @GetMapping("select")
    public JsonResult select(FeedbackQuery feedbackQuery) {
        log.debug("查询反馈列表:入参{}", feedbackQuery);
        List<FeedbackVO> list = feedbackService.select(feedbackQuery);
        log.debug("查询反馈列表:入参{},出参{}", feedbackQuery, list);
        return JsonResult.ok(list);
    }

    /**
     * 删除反馈
     * @param id 反馈id
     */
    @PostMapping("delete")
    public JsonResult delete(Long id) {
        log.debug("删除反馈:入参{}", id);
        feedbackService.delete(id);
        return JsonResult.ok();
    }
}
